From 695031df09ccb27171b23f5ab0c66358a87af3a6 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Thu, 20 Apr 2017 02:37:27 +0200 Subject: [PATCH] Fix the build --- debian/TODO | 22 ----- debian/cargo-checksums-prune.py | 28 ++++++ debian/cargo-vendor-pack.py | 163 ------------------------------- debian/cargo-vendor-unpack.py | 4 +- debian/cargohome/config | 5 + debian/make_orig_multi.sh | 1 + debian/patches/deps-adjust.patch | 63 ------------ debian/patches/series | 1 - debian/rules | 16 +-- 9 files changed, 39 insertions(+), 264 deletions(-) delete mode 100644 debian/TODO create mode 100755 debian/cargo-checksums-prune.py delete mode 100755 debian/cargo-vendor-pack.py create mode 100644 debian/cargohome/config delete mode 100644 debian/patches/deps-adjust.patch diff --git a/debian/TODO b/debian/TODO deleted file mode 100644 index 6c2995ed0..000000000 --- a/debian/TODO +++ /dev/null @@ -1,22 +0,0 @@ -The build currently fails with: - -[..] - -# Build final cargo binary and docs -/usr/bin/make -make[2]: Entering directory '/build/cargo-0.17.0' -/usr/bin/rustc -V -rustc 1.15.1 -/build/cargo-0.17.0/cargo-stage0 --version -cargo 0.15.0 (built 2016-11-26) -/build/cargo-0.17.0/cargo-stage0 build --target x86_64-unknown-linux-gnu --manifest-path /build/cargo-0.17.0//Cargo.toml --release --verbose -warning: custom registry support via the `registry.index` configuration is being removed, this functionality will not work in the future - Updating registry `file:///build/cargo-0.17.0/vendor/index` -error: no matching package named `backtrace` found (required by `error-chain`) -location searched: registry file:///build/cargo-0.17.0/vendor/index -version required: * -Makefile:128: recipe for target 'cargo-x86_64-unknown-linux-gnu' failed - -[..] - -We need to fix d/cargo-vendor-pack.py and probably -unpack.py as well diff --git a/debian/cargo-checksums-prune.py b/debian/cargo-checksums-prune.py new file mode 100755 index 000000000..5589799cb --- /dev/null +++ b/debian/cargo-checksums-prune.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +# Copyright: 2015 The Debian Project +# License: MIT-License or Apache-2.0 +# +# Helper to remove removed-files from .cargo-checksum +# TODO: rewrite to perl and add to dh-cargo, maybe? + +from collections import OrderedDict +import json +import os +import sys + +def main(pkgdir): + os.chdir(pkgdir) + with open(".cargo-checksum.json") as fp: + sums = json.load(fp, object_pairs_hook=OrderedDict) + + oldfiles = sums["files"] + newfiles = OrderedDict([entry for entry in oldfiles.items() if os.path.exists(entry[0])]) + sums["files"] = newfiles + + if len(oldfiles) > len(newfiles): + with open(".cargo-checksum.json", "w") as fp: + json.dump(sums, fp, separators=(',', ':')) + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else ".") diff --git a/debian/cargo-vendor-pack.py b/debian/cargo-vendor-pack.py deleted file mode 100755 index 84fab4bb7..000000000 --- a/debian/cargo-vendor-pack.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python - -# Copyright: 2015 The Debian Project -# License: MIT-License or Apache-2.0 -# -# Helper to generate a crate registry from local unpacked crates -# TODO: very bad code. It should be rewritten in perl and converted into dh_cargo - -import json -import os -import tarfile -import string -import pytoml -from dulwich.repo import Repo -import hashlib -from collections import OrderedDict - - -# TODO: hackish, at best. features need to be properly parsed -def parse_deps(toml): - deps=[] - if 'dependencies' not in toml: - return deps - d = toml['dependencies'] - if 'target' in toml: - t = toml['target'] - if 'x86_64-unknown-linux-gnu' in t: - t = t['x86_64-unknown-linux-gnu'] - if 'dependencies' in t: - d.update(t['dependencies']) - for k, v in d.iteritems(): - opt = False - defa = True - if isinstance(v, dict): - opt = v.get('optional', opt) - v = '*' - i = { - "default_features": defa, - "features": [], - "kind": "normal", - "name": k, - "optional": opt, - "req": v, - "target": None - } - deps.append(i) - if 'build-dependencies' not in toml: - return deps - d = toml['build-dependencies'] - for k, v in d.iteritems(): - opt = False - defa = True - if isinstance(v, dict): - opt = v.get('optional', opt) - v = '*' - i = { - "default_features": defa, - "features": [], - "kind": "build", - "name": k, - "optional": opt, - "req": v, - "target": None - } - deps.append(i) - if 'dev-dependencies' not in toml: - return deps - d = toml['dev-dependencies'] - for k, v in d.iteritems(): - opt = False - defa = True - if isinstance(v, dict): - opt = v.get('optional', opt) - v = '*' - i = { - "default_features": defa, - "features": [], - "kind": "dev", - "name": k, - "optional": opt, - "req": v, - "target": None - } - deps.append(i) - return deps - -def main(): - curdir = os.getcwd() - depsdir = os.path.join(curdir, "deps") - vendordir = os.path.join(curdir, "vendor") - cachedir = os.path.join(vendordir, "cache") - indexdir = os.path.join(vendordir, "index") - cargocfgdir = os.path.join(curdir, ".cargo") - for d in [cachedir, indexdir]: - if not os.path.exists(d): - os.makedirs(d) - - indexdict = OrderedDict() - for crate in os.listdir(depsdir): - if os.path.isdir(os.path.join(depsdir, crate)) and not crate.startswith('.'): - (name, ver) = string.rsplit(crate, '-', 1) - print("Found %s ver. %s (at %s)" % (name, ver, os.path.join(depsdir, crate))) - destdir=(os.path.join(cachedir, name, ver)) - os.makedirs(destdir) - tarcrate = os.path.join(destdir, "download") - tar = tarfile.open(tarcrate, "w:gz", format=tarfile.USTAR_FORMAT) - tar.add(os.path.join(depsdir, crate), arcname=crate) - tar.close() - - manif = None - with open(os.path.join(depsdir,crate,'Cargo.toml'), 'rb') as f: - manif = pytoml.load(f) - - nestdir = None - if len(name) >= 4: - nestdir = os.path.join(indexdir, name[0:2], name[2:4]) - else: - nestdir = os.path.join(indexdir, '3', name[0]) - - cksum = hashlib.sha256(open(tarcrate, 'rb').read()).hexdigest() - indexdict[name] = OrderedDict([ - ('name', name), - ('vers', ver), - ('deps', parse_deps(manif)), - ('features', manif.get('features',{})), - ('cksum', cksum), - ('yanked', False) - ]) - if not os.path.exists(nestdir): - os.makedirs(nestdir) - with open(os.path.join(nestdir, name), 'a') as outfile: - json.dump(indexdict[name], outfile, sort_keys=False) - outfile.write('\n') - - - configjson = { - 'api': '', - 'dl': "file://{0}".format(cachedir) - } - with open(os.path.join(indexdir, 'config.json'), 'w') as outfile: - json.dump(configjson, outfile) - - p = [] - for dirpath, _, paths in os.walk(indexdir): - for f in paths: - p.append(os.path.relpath(os.path.join(dirpath,f), indexdir)) - - repo=Repo.init(indexdir) - for f in paths: - repo.stage(p) - repo.do_commit(b"Fake commit", committer=b"Cargo debhelper ") - - cfg="""[registry] -index = "file://{0}" -""" - if not os.path.exists(cargocfgdir): - os.makedirs(cargocfgdir) - - with open(os.path.join(cargocfgdir, "config"), "w") as cfgfile: - cfgfile.write(cfg.format(indexdir)) - -if __name__ == "__main__": - main() diff --git a/debian/cargo-vendor-unpack.py b/debian/cargo-vendor-unpack.py index 0e9f0b9c0..1ab1406ce 100755 --- a/debian/cargo-vendor-unpack.py +++ b/debian/cargo-vendor-unpack.py @@ -1,10 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright: 2015 The Debian Project # License: MIT-License or Apache-2.0 # # Helper to unpack a local crate registry to original sources -# TODO: rewrite to perl, maybe? +# TODO: rewrite to perl and add to dh-cargo, maybe? import os import tarfile diff --git a/debian/cargohome/config b/debian/cargohome/config new file mode 100644 index 000000000..44eb42b78 --- /dev/null +++ b/debian/cargohome/config @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with = "dh-cargo-registry" + +[source.dh-cargo-registry] +directory = "../deps" diff --git a/debian/make_orig_multi.sh b/debian/make_orig_multi.sh index b15a6b206..040b0c62d 100755 --- a/debian/make_orig_multi.sh +++ b/debian/make_orig_multi.sh @@ -51,6 +51,7 @@ cargo vendor --explicit-version --verbose deps # Unpack artifacts and clean embedded libs ${WORKDIR}/debian/cargo-vendor-unpack.py grep -v '^#' ${DEPS_FILTER} | xargs -I% sh -c 'rm -rf deps/%' +for i in deps/*; do ${WORKDIR}/debian/cargo-checksums-prune.py "$i"; done # Report any suspicious files cp -R deps deps-scan diff --git a/debian/patches/deps-adjust.patch b/debian/patches/deps-adjust.patch deleted file mode 100644 index 7d06c30bc..000000000 --- a/debian/patches/deps-adjust.patch +++ /dev/null @@ -1,63 +0,0 @@ -From: Luca Bruno -Description: Adjust deps dependencies - This is a workaround for bugs in the embedding script -Forwarded: not-needed - ---- a/deps/tar-0.4.9/Cargo.toml -+++ b/deps/tar-0.4.9/Cargo.toml -@@ -25,7 +25 @@ - tempdir = "0.3" -- --[target."cfg(unix)".dependencies] --xattr = { version = "0.1.7", optional = true } -- --[features] --default = ["xattr"] ---- a/deps/libgit2-sys-0.6.6/Cargo.toml -+++ b/deps/libgit2-sys-0.6.6/Cargo.toml -@@ -20,2 +20,3 @@ - libz-sys = ">= 0" -+openssl-sys = { version = "0.9", optional = true } - -@@ -26,5 +27,2 @@ - --[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies] --openssl-sys = { version = "0.9", optional = true } -- - [features] ---- a/deps/git2-0.6.3/Cargo.toml -+++ b/deps/git2-0.6.3/Cargo.toml -@@ -22,4 +22,2 @@ - libgit2-sys = { path = "libgit2-sys", version = "0.6.4" } -- --[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies] - openssl-sys = { version = "0.9.0", optional = true } ---- a/deps/fs2-0.3.0/Cargo.toml -+++ b/deps/fs2-0.3.0/Cargo.toml -@@ -10,3 +10,3 @@ - --[target.'cfg(unix)'.dependencies] -+[dependencies] - libc = "0.2.2" ---- a/deps/libssh2-sys-0.2.5/Cargo.toml -+++ b/deps/libssh2-sys-0.2.5/Cargo.toml -@@ -17,4 +17,2 @@ - libc = "0.2" -- --[target."cfg(unix)".dependencies] - openssl-sys = "0.9" ---- a/deps/curl-sys-0.3.6/Cargo.toml -+++ b/deps/curl-sys-0.3.6/Cargo.toml -@@ -22,4 +22,2 @@ - libc = "0.2" -- --[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies] - openssl-sys = "0.9" ---- a/deps/curl-0.4.1/Cargo.toml -+++ b/deps/curl-0.4.1/Cargo.toml -@@ -13,5 +13,2 @@ - curl-sys = { path = "curl-sys", version = "0.3" } -- --# Unix platforms use OpenSSL for now to provide SSL functionality --[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies] - openssl-sys = "0.9.0" diff --git a/debian/patches/series b/debian/patches/series index 91f55488e..03b84cb45 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,3 +1,2 @@ clean-cargo-deps.patch -deps-adjust.patch local-jquery.patch diff --git a/debian/rules b/debian/rules index f42a32132..a2f8ef1a6 100755 --- a/debian/rules +++ b/debian/rules @@ -11,7 +11,7 @@ DEB_HOST_RUST_TYPE := $(call rust_cpu,$(DEB_HOST_GNU_CPU))-unknown-$(DEB_HOST_GN DEB_TARGET_RUST_TYPE := $(call rust_cpu,$(DEB_TARGET_GNU_CPU))-unknown-$(DEB_TARGET_GNU_SYSTEM) # Cargo looks for config in and writes cache to $CARGO_HOME/ -export CARGO_HOME = $(CURDIR)/.cargohome +export CARGO_HOME = $(CURDIR)/debian/cargohome # Ask cargo to be verbose when building export VERBOSE = 1 @@ -25,8 +25,6 @@ DEPSDIR := $(CURDIR)/deps override_dh_auto_configure: cp -a $(CURDIR)/Cargo.lock $(CURDIR)/.Cargo.lock.orig - # Prepare a fake registry by packing all deps - ./debian/cargo-vendor-pack.py override_dh_auto_build: ifneq ($(filter stage0,$(DEB_BUILD_PROFILES)),) @@ -42,12 +40,9 @@ ifneq ($(filter stage0,$(DEB_BUILD_PROFILES)),) --host=$(DEB_HOST_RUST_TYPE) \ --target=$(DEB_TARGET_RUST_TYPE) # Workaround for https://github.com/rust-lang/cargo/issues/1423 - mv $(DEPSDIR) $(CURDIR)/.deps - ln -s `find $(CURDIR)/.deps -name 'cargo-*' -type f -executable` $(CURDIR)/cargo-stage0 + ln -s `find $(DEPSDIR) -name 'cargo-*' -type f -executable` $(CURDIR)/cargo-stage0 else ln -s `which cargo` $(CURDIR)/cargo-stage0 - # Workaround for https://github.com/rust-lang/cargo/issues/1423 - mv $(DEPSDIR) $(CURDIR)/.deps endif # Configure to build cargo using the just-built stage0 ./configure \ @@ -63,24 +58,19 @@ ifeq (,$(findstring nodoc,$(DEB_BUILD_PROFILES))) cd target/doc/ && rm -f jquery.js && ln -s /usr/share/javascript/jquery/jquery.js endif - # Restore from workarounds - mv $(CURDIR)/.deps $(DEPSDIR) - override_dh_auto_clean: -mv $(CURDIR)/.Cargo.lock.orig $(CURDIR)/Cargo.lock - -mv $(CURDIR)/.deps $(DEPSDIR) dh_auto_clean -$(RM) -r $(CURDIR)/deps/*.rlib \ $(CURDIR)/deps/build_script* \ $(CURDIR)/deps/cargo* \ $(CURDIR)/deps/*.o \ $(CURDIR)/target/ \ - $(CURDIR)/.cargo/ \ + $(CURDIR)/.cargo \ $(CURDIR)/config.mk \ $(CURDIR)/config.stamp \ $(CURDIR)/Makefile \ $(CURDIR)/cargo-stage0 \ - $(CARGO_HOME) \ $(VENDORDIR) override_dh_auto_install: -- 2.30.2